﻿using System;
using CommonFramework.Serialize.BytesArray;
using LitJson;

namespace Net
{
    public abstract class NetPacket:IBytesSerializable
    {
        /// <summary>
        /// 消息包内容序列化
        /// </summary>
        public virtual void WriteToBytes(BytesWriter writer)
        {
        }
        /// <summary>
        /// 消息包内容反序列化
        /// </summary>
        public virtual void ReadFromBytes(BytesReader reader)
        {
        }

        public string PacketName => NetUtil.GetPacketName(this.GetType());
    }

    public class NetPakcetMove : NetPacket
    {
        public string desc;
        public float x;
        public float y;
        public float z;

        public override void WriteToBytes(BytesWriter writer)
        {
            writer.WriteString(desc);
            writer.WriteFloat(x);
            writer.WriteFloat(y);
            writer.WriteFloat(z);
        }
        public override void ReadFromBytes(BytesReader reader)
        {
            this.desc = reader.ReadString();
            this.x = reader.ReadFloat();
            this.y = reader.ReadFloat();
            this.z = reader.ReadFloat();
        }
    }
}